package com.zhitxx.progress_webview

open class IndicatorHandler {
    lateinit var progressSpec: ProgressSpec


    fun setProgress(newProgress: Int) {
        if (newProgress == 0) {
            reset()
        } else if (newProgress in 1..10) {
            show()
        } else if (newProgress in 10..95) {
            setProgressBar(newProgress)
        } else {
            setProgressBar(newProgress)
            finish()
        }
    }

    private fun setProgressBar(newProgress: Int) {
        progressSpec.setProgress(newProgress)

    }


    fun show() {
        progressSpec.show()
    }

    fun reset() {
        progressSpec.reset()
    }

    fun finish() {
        progressSpec.hide()
    }

    companion object {
        var instances = IndicatorHandler()
    }

    open fun initWebProgress(progressSpec: ProgressSpec): IndicatorHandler {
        this.progressSpec = progressSpec
        return this
    }
}